package characterCreator;

import java.util.Arrays;
import java.util.Random;

public class Die {
	private int value;
	private int[] rolls;
	private Random random;

	public Die() {
		value = 0;
		random = new Random(System.currentTimeMillis());
	}
	
	public int Roll(int numberOfRolls, int typeOfDie) {
		value = 0;
		random = new Random(System.currentTimeMillis());
		
		for (int i=0; i<numberOfRolls; i++) {
			value += random.nextInt((typeOfDie)+1);
		}
		
		return value;
	}
	
	public int RollCharacter(int numberOfRolls, int typeOfDie, int numDrop) {
		value = 0;
		random = new Random(System.currentTimeMillis());
		rolls = new int[numberOfRolls];

		while (value<3) {
			for (int i=0; i<numberOfRolls; i++) {
				rolls[i] = random.nextInt((typeOfDie)+1);
			}
			Arrays.sort(rolls);

			for (int i=numDrop; i<numberOfRolls; i++) {
				value += rolls[i];
			}
		}
		return value;
	}
	
	
	public int calcAdjustment(int value) {
		if (value <= 3 ) {
			value = -3;
		} else if (value <= 5) {
			value = -2;
		} else if (value <= 8) {
			value = -1;
		} else if (value <= 12) {
			value = 0;
		} else if (value <= 15) {
			value = 1;
		} else if (value <= 17) {
			value = 2;
		} else {
			value = 3;
		}
		return value;
	}
}
